
<script type="text/javascript">
    $(document).ready(function() {
        $("#selectAll").click(function() {
            if ($(this).attr("checked") == "checked") {
                $(":checkbox").attr("checked", true);
            } else {
                $(":checkbox").attr("checked", false);
            }
        });

    });
</script> 
<script type="text/javascript">
    $(function() {
        $('.tree li:has(ul)').addClass('parent_li').find(' > span').attr('title', 'Collapse this branch');
        $('.tree li.parent_li > span').on('click', function(e) {
            var children = $(this).parent('li.parent_li').find(' > ul > li');
            if (children.is(":visible")) {
                children.hide('fast');
                $(this).attr('title', 'Expand this branch').find(' > i').addClass('icon-plus-sign').removeClass('icon-minus-sign');
            } else {
                children.show('fast');
                $(this).attr('title', 'Collapse this branch').find(' > i').addClass('icon-minus-sign').removeClass('icon-plus-sign');
            }
            e.stopPropagation();
        });
    });</script>
<script type="text/javascript">
    $(function() {
        $("#Event_Shop_CX").click(function() {
            document.getElementById("Event_Shop_CX_View").style.display = '';
            document.getElementById("Event_Clothes_CX_View").style.display = 'none';
        });
        $("#Event_Clothes_CX").click(function() {
            document.getElementById("Event_Shop_CX_View").style.display = 'none';
            document.getElementById("Event_Clothes_CX_View").style.display = '';
        });
    });</script>

<legend>
    <h4><?php echo $control->getAjaxLink(array('name' => '功能列表', 'id' => 'showEventList')); ?>\  
        <?php
        echo $control->getAjaxLink(array('name' => '预订项配置列表', 'id' => 'showBookableList'), array(
            'eventId' => $eventId));
        ?>\
        <?php echo '管理预订项'; ?>
    </h4>
</legend>

<?php
$totalRows = 0;
if (!isset($availableList) || $availableList == NULL) {
    $availableList = array();
    if (isset($findText) && $findText != NULL) {
        if (isset($findContext) && $findContext != NULL) {
            $findContext = unserialize($findContext);
        } else {
            $findContext = Blyn::app()->getUIManager()->getCurrentScreen()->getContextVariable('findContext');
        }

        if ($findContext == NULL) {
            $availableList = Blyn::app()->getActiveApp()->findByFindText($findText);
            $totalRows = Blyn::app()->getActiveApp()->findCountByFindText($findText);
        } else {
            $availableList = Blyn::app()->getActiveApp()->findByFindText($findText, $findContext);
            $totalRows = Blyn::app()->getActiveApp()->findCountByFindText($findText);
        }
    }
}
?>
<?php
$rowsPerPage = 10;
if (!empty($_POST))
    $pageNo = $_POST['curPageNo'];
else
    $pageNo = 1;
$totalpages = ceil($totalRows / $rowsPerPage);
?>

<table class="table table-hover">
    <thead>
        <tr>
            <th>
                <input type="checkbox"  id="selectAll"> 
            </th>
            <th><?php echo '场地'; ?></th>
            <th><?php echo '日期'; ?></th>
            <th><?php echo '开始时间'; ?></th>
            <th><?php echo '结束时间'; ?></th>
            <th><?php echo '预定状态'; ?></th>
            <th><?php echo '操作'; ?></th>
        </tr> 
    </thead>
    <fieldset>
        <tbody>
            <?php
            foreach ($availableList as $id => $bookingItem) {
                //$startTime = $bookingItem->getItem('startTime')->value;
                //$endTime = $bookingItem->getItem('endTime')->value;
                $date = date('Y-m-d', $bookingItem->getItem('startTime')->value);
                $startTime = date('G:i:s', $bookingItem->getItem('startTime')->value);
                $endTime = date('G:i:s', $bookingItem->getItem('endTime')->value);
                ?>
                <tr>
                    <td><label class="checkbox">
                            <input type="checkbox" name="checkbox[]" value="<?php echo $id; ?>"> 
                        </label></td>
                    <td> <?php echo $bookingItem->getItem('courtDisplayName')->value; ?> </td>
                    <td> <?php echo $date; ?> </td> 
                    <td> <?php echo $startTime; ?> </td>       
                    <td> <?php echo $endTime; ?> </td>    
                    <td> <?php echo  Yii::t('BWeSport', $bookingItem->getItem('bookingStatus')->value); ?> </td>    
                    <td>
                        <div class="row-fluid">                         
                            <?php
                            $id = $bookingItem->getId();
                            $control1 = new BUIControl('bookingButton' . $id);
                            $data = array(
                                'bookingId' => $bookingItem->getId(),
                            );
                            if (isset($findText)) {
                                $data['findText'] = $findText;
                            }
                            if (isset($findContext)) {
                                $data['findContext'] = $findContext;
                            }
                            $control1->addRenderView('toggleButton', 'booking_add_toggleButton', $data);
                            $control1->render();
                            ?>                             
                        </div>                      
                    </td>
                </tr>
            <?php } ?>
        </tbody>
    </fieldset>
</table>
<div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
</div>
<?php
$control3 = new BUIControl('showPayList');
?>
<div id="myModal2" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">    
    <div class="modal-body" >
        <?php
        $control3->render();
        ?>
    </div>
    <div class="modal-footer">
        <?php
        $data = array();
        $data['htmlOptions'] = array('class' => 'btn', 'data-dismiss' => 'modal', 'aria-hidden' => 'true');
        if (isset($findText))
            $data['findText'] = $findText;
        if (isset($findContext))
            $data['findContext'] = serialize($findContext);
        echo $control->getAjaxLink(array('name' => '关闭', 'id' => 'showBookingList'), $data);
        ?>
    </div>
</div>
<div><input type="hidden" name="curPageNo" value="1"></div>

<div class="pagination">  
    <ul>  
        <li <?php
        $prevStr = Yii::t('site', '<<');
        $nextStr = Yii::t('site', '>>');
        $disabled = ($pageNo == 1 || $totalpages == 0);
        if ($disabled)
            echo "class='active'";
        ?>>
                <?php
                if ($pageNo + 1 > $totalpages)
                    $curPageNoStr = strval($totalpages);
                else
                    $curPageNoStr = strval($pageNo + 1);

                if ($disabled) {
                    echo '<a href="javascript:void()">' . $prevStr . '</a>';
                } else {
//                echo $control->getAjaxLink($prevStr, array('data'=>$curPageNoStr));
                    echo $control->getAjaxLink(array('name' => $prevStr, 'id' => 'showSelectedPageBookingList'), array(
                        'curPageNo' => $curPageNoStr,
                        'htmlOptions' => array('enctype' => 'multipart/form-data',
                    )));
                }
                ?>
        </li>  
        <?php
        for ($j = 0; $j < $totalpages; $j++) {
            $curPageNoStr = strval($j + 1);
            ?>
            <li <?php
            $disabled = ($pageNo == $j + 1);
            if ($disabled)
                echo "class='active'";
            ?>>
                    <?php
                    if ($disabled) {
                        echo '<a href="javascript:void()">' . $curPageNoStr . '</a>';
                    } else {
//                echo $screen->getAjaxLink($curPageNoStr);
                        echo $control->getAjaxLink(array('name' => '第' . $curPageNoStr . '页', 'id' => 'showSelectedPageBookingList'), array(
                            'curPageNo' => $curPageNoStr,
                            'htmlOptions' => array('enctype' => 'multipart/form-data',
                        )));
                    }
                    ?>
            </li>  
        <?php }
        ?>
        <li <?php
        $disabled = ($pageNo == $totalpages || $totalpages == 0);
        if ($disabled)
            echo "class='active'";
        ?>>
                <?php
                if ($pageNo < 2)
                    $curPageNoStr = '1';
                else
                    $curPageNoStr = strval($pageNo - 1);

                if ($disabled) {
                    echo '<a href="javascript:void()">' . $nextStr . '</a>';
                } else {
//                echo $screen->getAjaxLink($nextStr, array('data'=>$curPageNoStr));
                    echo $control->getAjaxLink(array('name' => $nextStr, 'id' => 'showSelectedPageBookingList'), array(
                        'curPageNo' => $curPageNoStr,
                        'htmlOptions' => array('enctype' => 'multipart/form-data',
                    )));
                }
                ?>
        </li> 
        <li class="active">
            <a href="javascript:void()">前一页</a>    </li>  
        <li class="active">
            <a href="javascript:void()">1</a>    </li>  
        <li class="active">
            <a href="javascript:void()">后一页</a>    </li>  
        <li >
            <?php
            $data = array();
            $data['htmlOptions'] = array('class' => 'btn btn-primary');
            $findContext = array();
            if (!isset($findContext) || !is_array($findContext))
                $findContext = array();
            if (isset($findText))
                $findContext['findText'] = $findText;

            Blyn::app()->getUIManager()->getCurrentScreen()->addContextVariable('findContext', $findContext);
            echo $control3->getAjaxLink(
                    array(
                'name' => '进入支付',
                'id' => 'showPayBooking'), array(
                'ajaxOptions' => array(
                    'complete' => 'function(){$("#ajax-loaderdiv").hide();$("#myModal2").modal("show");}')
            ));
            ?>
        </li>
    </ul>  
</div>